<template>
  <div class="box">
    <!-- 页面顶部的bar页面 -->
    <div class="boxtop">
      <van-nav-bar  title="车系选择">
      </van-nav-bar>
    </div>
    <!-- 搜索栏 -->
    <div class="searchbox">
      <van-search
      v-model="value"
      placeholder="请输入搜索关键词"
      input-align="center"
    />
    <!-- 索引栏 -->
    <van-index-bar highlight-color >
      <span class="allcar">全部</span>
      <div v-for="(item,index) in this.carSerier" @click="clickCarSrier(item)" :key="index">
        <!-- 这里不需要ABCD这些索引 -->
        <!-- <van-index-anchor >
        </van-index-anchor> -->
        <span class="seriesName">{{item.seriesName}}</span>
      </div>
      <!-- 在文本框中应该循环数组，然后添加点击事件，或者根据自己的索引值然后处理事件 -->
    </van-index-bar>
</div>
  </div>
</template>
<script>
import { newSerise } from '@/api/comput'
export default {
  data () {
    return {
      value: '',
      // 车系选择
      carSerier: []
    }
  },
  created () {
    this.getAllInfo()
  },
  methods: {
    async getAllInfo () {
      // 请求新车车系
      try {
        const { data } = await newSerise()
        console.log(data)
        this.carSerier = data.data
      } catch (err) {
        this.$toast('获取失败')
      }
      // console.log(this.$route.query.nameId)
      // try {
      //   console.log(this.$route.query.nameId)
      //   const { data } = await CarSeries({ brandId: this.$route.query.nameId })
      //   this.carSerier = data.data
      //   console.log(data.data)
      // } catch (err) {
      //   this.$toast('获取失败')
      // }
    },
    ClickText () {
      console.log('打印搜索栏')
      this.$router.push('/carname')
    },
    clickCarSrier (val) {
      console.log(val)
      // 将车系名字保存在vuex中
      this.$store.commit('getComputeSerise', val.seriesName)
      this.$router.push({ path: '/computemodel', query: { seriesCode: val.seriesCode } })
      // 然后进项跳转
      // 将车系存入vuex中
      // this.$store.commit('gainserier', val.seriesName)
      // 路由跳转
      // this.$router.push({ path: '/carmodel', query: { serierIn: val.seriesId } })
    }
  }
}
</script>
<style lang="less" scoped>
.box{
  // background-color: #f6f6f9;
  .allcar{
    display: inline-block;
    margin-left: 10px;
    width: 40px;
    height: 16px;
    font-size: 13px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #A4A4A4;
    line-height: 16px;
    }
    .seriesName{
      display: inline-block;
      height: 21px;
      font-size: 14px;
      font-weight: 400;
      margin-left: 10px;
      margin-top: 30px;
      font-family: PingFangSC-Regular, PingFang SC;
    }
}
</style>
